#include <stdio.h>
int NUM = 9;

int huiPrint(int a[][9],int x, int y){
	if (!(x && y))
		return -1;
	int add_x = x ;
	int add_y = y ;
	int start_x = 0;
	// each loop should have a change. so the begin start_y should be -1 + 1 = 0 ;
	int start_y = -1;
	int i = 0;
	//add_y is 1 bigger then add_x

	while(1){
		
		if (!(add_y && add_x))
			break;
		
		for (i = 1; i <= add_y; ++i)
		{
			printf("%d,",a[start_x][i + start_y] );
		}
		add_y--;
		start_y = i + start_y -1;

		if (!(add_y && add_x))
			break;

		for (i = 1; i < add_x; ++i)
		{
			printf("%d,", a[i + start_x][start_y] );
		}
		add_x--;
		start_x = i + start_x - 1;
		
		if (!(add_y && add_x))
			break;

		for ( i = -1; i >= - add_y; --i)
		{
			printf("%d,",a[start_x][i + start_y] );
		}
		add_y--;
		start_y = i + start_y + 1;
		
		if (!(add_y && add_x))
			break;

		for ( i = -1; i > -add_x; --i)
		{
			printf("%d,",a[start_x +i][start_y] );
		}
		add_x--;
		start_x = i+ start_x + 1;

		
	}
	return 0;
}

int main(int argc, char const *argv[])
{
	int a[9][9];
	int count = 1;
	for (int i = 0; i < NUM; ++i)
	{
		for(int j = 0; j < NUM; ++j)
			{
				a[i][j] = count;
				printf("%d ", a[i][j]);
				count ++; 
			} 
		printf("\n");
	}
	huiPrint(a, NUM, NUM);
	return 0;
}